package com.bonc.ioc.controller;

import com.bonc.ioc.base.controller.BaseController;
import com.bonc.ioc.base.page.PageResult;
import com.bonc.ioc.common.util.AppReply;
import com.bonc.ioc.service.KnowledgesService;
import com.bonc.ioc.validation.AppAuthAnnotation;
import com.bonc.ioc.vo.KnowledgesVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.*;

/**
 * 内容展示相关接口 知识产权
 *
 * @author xsy
 * @date 2021/3/7 13:27
 */

@RestController
@RequestMapping("/knowledge")
@Slf4j
public class KnowledgeController extends BaseController {

    @Autowired
    private KnowledgesService knowledgesService;

    /**
     * saveAddictsInfo
     * 保存 知识产权 信息
     *
     * @param item:
     * @return com.bonc.ioc.common.util.AppReply
     * @author wangqinglin
     * @date 2021/3/18 15:41
     * @change 2021/3/18 15:41 by q8541q@163.com for init
     * @since 1.0.0
     */
    @PostMapping("/save")
    @AppAuthAnnotation
    public AppReply saveAddictsInfo(@RequestBody KnowledgesVo item) {
        return AppReply.success(knowledgesService.save(item));
    }

    /**
     * deleteMadInfo
     * 删除 知识产权 信息
     *
     * @param id:
     * @return com.bonc.ioc.common.util.AppReply
     * @author wangqinglin
     * @date 2021/3/18 15:41
     * @change 2021/3/18 15:41 by q8541q@163.com for init
     * @since 1.0.0
     */
    @GetMapping("/delete")
    @AppAuthAnnotation
    public AppReply deleteMadInfo(@RequestParam String id) {
        return AppReply.success(knowledgesService.deleteByPrimaryKey(id));
    }

    /**
     * getStandardInfo
     * 获取知识产权 详情
     *
     * @param id:
     * @return com.bonc.ioc.common.util.AppReply
     * @author wangqinglin
     * @date 2021/3/18 15:44
     * @change 2021/3/18 15:44 by q8541q@163.com for init
     * @since 1.0.0
     */
    @GetMapping("/getKnowledgeInfo")
    public AppReply getStandardInfo(@RequestParam String id) {
        return AppReply.success(knowledgesService.selectByPrimaryKey(Long.valueOf(id)));
    }

    @GetMapping("/getKnowledgeByPage")
    public AppReply getStandardInfoByPage() throws BindException {
        PageResult pageResult = knowledgesService.selectStandardInfoByPage(getPageData());
        return AppReply.success(pageResult);
    }

    @GetMapping("/getKnowledgeListInfos")
    public AppReply getKnowlegdeListInfos() {
        return AppReply.success(knowledgesService.getKnowledgeListInfos());
    }
}
